package training.project.app.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import training.project.app.domain.Client;
import training.project.app.domain.Flight;
import training.project.app.domain.FlightClient;
import training.project.app.repository.ClientDao;
import training.project.app.service.ClientService;
import training.project.app.service.FlightClientService;

@Service
@Transactional
public class ClientServiceImpl implements ClientService
	{
		@Autowired
		private ClientDao clientRepository;
		@Autowired
		private FlightClientService flightClientService;
		public void saveClient(Client client)
			{
				clientRepository.save(client);
			}

		public void deleteClient(Client client)
			{
				clientRepository.delete(client);
			}

		public void updateClient(Client client)
			{
				clientRepository.update(client);
			}

		public List<Client> getClients()
			{
				List<Client> clients = clientRepository.findAll();
				return clients;
			}

		@Override
		public Client loadUserByCredentials(String login, String password)
			{
				Client client = clientRepository.findByCredentials(login, password);
				return client;
			}

		@Override
		public Client getClientById(Integer id)
			{
				return clientRepository.findById(id);
			}

		@Override
		public void bookFlight(Flight flight, Client client)
			{
				
				
			}

		@Override
		public List<FlightClient> getFlightClients(Client client)
			{
				List<FlightClient> flights = flightClientService.getFlightClients(client.getClientId());
				return flights;
			}
		
		
	}
